package com.cs.store.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cs.domain.entity.ShopCar;
import com.cs.domain.vo.ShopCarVo;
import com.cs.domain.vo.StoreGoodsVo;
import com.cs.store.dao.IShopCarDao;
import com.cs.store.dao.IShopCarVoDao;
import com.cs.store.dao.IStoreGoodsVoDao;
import com.cs.store.service.IShopCarService;
import com.cs.user.dao.IUserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShopCarServiceImpl implements IShopCarService {
    @Autowired
    private IShopCarDao iShopCarDao;

    @Autowired
    private IStoreGoodsVoDao iStoreGoodsVoDao;
    @Autowired
    private IShopCarVoDao iShopCarVoDao;
    @Autowired
    private IUserDao iUserDao;


    /**
     * 根据店铺商品id查找storegoods表商品信息
     *
     * @param stGoodsId
     * @return
     */
    @Override
    public StoreGoodsVo findBystGoodsId(Long stGoodsId) {

        QueryWrapper wrapper = new QueryWrapper<>();
        wrapper.eq("store_goods_id", stGoodsId);
        return iStoreGoodsVoDao.selectOne(wrapper);
    }


    /**
     * 添加购物车
     *
     * @param
     * @return
     */
    @Override
    public Integer addShopCar(ShopCar shopCar) {
        return iShopCarDao.insert(shopCar);
    }


    /**
     * 查看购物车
     *
     * @param
     * @return
     */
    @Override
    public List<ShopCarVo> findCar(String username, Long storeId) {
        QueryWrapper wrapper = new QueryWrapper<>();
        wrapper.eq("user_username", username);
        wrapper.eq("store_id", storeId);
        return iShopCarVoDao.selectList(wrapper);
    }

    @Override
    public Long finduserId(String username) {
        QueryWrapper Qwrapper = new QueryWrapper<>();
        Qwrapper.eq("user_username", username);
        return iUserDao.selectOne(Qwrapper).getId();
    }

    @Override
    public Integer deleCarGoods(Long carId) {
        QueryWrapper Qwrapper = new QueryWrapper<>();
        Qwrapper.eq("car_id", carId);
        iShopCarDao.delete(Qwrapper);
        return 1;
    }

}
